/**
 * 文档节管理初始化
 */
var CdcOrigsection = {
    id: "CdcOrigsectionTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CdcOrigsection.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '代码', field: 'code', align: 'center', valign: 'middle', sortable: true},
        {title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true},
        {title: '所属章', field: 'chapterId', align: 'center', valign: 'middle', sortable: true},
        {title: '文档类型', field: 'docTypeId', align: 'center', valign: 'middle', sortable: true},
        {title: '内容', field: 'content', align: 'center', valign: 'middle', sortable: true},
        {title: '是否有结果', field: 'isStructed', align: 'center', valign: 'middle', sortable: true},
        {title: '是否有效', field: 'isActive', align: 'center', valign: 'middle', sortable: true},
        {title: '操作', field: 'id', align: 'center', width: '120px', valign: 'middle',formatter:function(value,row,index){
    		var _html = '<a href="javascript:CdcOrigsection.edit(\''+row.id+'\')" title="修改"><i class="hisui-icon icon-write-order"></i></a>';
    		_html += '<a href="javascript:CdcOrigsection.del(\''+row.id+'\',\''+row.name+'\')" title="删除"><i class="hisui-icon icon-cancel"></i></a>';
    		return _html;
        }}];
};

/**
 * 检查是否选中
 */
CdcOrigsection.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CdcOrigsection.seItem = selected[0];
        return true;
    }
};

/**
 * 点击新增文档节
 */
CdcOrigsection.add = function () {
    var index = Sys.open('新增文档节',Sys.backendPath + '/cdc/cdcorigsection/to_add',['800px', '420px']);
    this.layerIndex = index;
};

/**
 * 打开查看文档节详情
 */
CdcOrigsection.edit = function (id) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        flag = true;
    }
	if (flag) {
    	var index = Sys.open('文档节详情',Sys.backendPath + '/cdc/cdcorigsection/to_update/' + id,['800px', '420px']);
        this.layerIndex = index;
    }
};

/**
 * 删除文档节
 */
CdcOrigsection.del = function (id,name) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        name = this.seItem.name
        flag = true;
    }
	if (flag) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/cdc/cdcorigsection/delete", function (data) {
	            Sys.success("删除成功!");
	            CdcOrigsection.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("cdcOrigsectionId",id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除文档节?",operation);
    }
};

/**
 * 查询文档节列表
 */
CdcOrigsection.search = function () {
    var queryData = {};
    queryData['description'] = $("#description").val();
    queryData['chapterId'] = $("#chapterId").val();
    queryData['docTypeId'] = $("#docTypeId").val();
    queryData['content'] = $("#content").val();
    queryData['isStructed'] = $("#isStructed").val();
    queryData['isActive'] = $("#isActive").val();
    CdcOrigsection.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = CdcOrigsection.initColumn();
    var table = new BSTable(CdcOrigsection.id, Sys.backendPath + "/cdc/cdcorigsection/list", defaultColunms);
    table.setPaginationType("server");
    CdcOrigsection.table = table.init();
});
